package com.example.springbootbook.mapper;

import com.example.springbootbook.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {
    @Select("select * from book_info where status!=0 " +
            "order by id desc limit #{offset},#{pageSize}")
    List<BookInfo> getBookInfoByPage(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
    //给你个建议哈，不要用这种方式写SQL，比较麻烦，不如咱们传统的那种方式~
    //这里要用就拿param起别名来做
    //不是JDBC 这种哥都没用过 但是个人感觉没有原来的那种方便
    //plus上有分页插件，到时候可以学一学那个，那个更智能


    @Select("select count(1) from book_info where status!=0")
    Integer getTotal();

    @Insert("insert into book_info(book_name,author,count,price,publish,status) " +
            "values(#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer addBook(BookInfo bookInfo);

    @Select("select * from book_info where id=#{id}")
    BookInfo queryBookInfoById(Integer id);

    Integer updateBook(BookInfo bookInfo);
}
